<?php

include_once 'Statement.php';
include_once 'StatementCollection.php';

/**
 * Represents a case statement
 * 
 * This class is meant to be used as a part of the SwitchStatement class
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic 
 * @example ../Examples/SwitchStatementExample.php
 */

class CaseStatement extends Statement
{
    /**
     * The CaseStatement constructor
     * 
     * @param Expression $CaseExpression The expression to be compared to SwitchStatement condition
     * @param StatementCollection $Statements The statements to be executed
     * @param bool $hasBreak Does this case statement end with break
     * @param bool $isDefault Is this a default case statement
     */
    
    public function __construct(
        Expression $CaseExpression, StatementCollection $Statements = null, 
        $hasBreak = true, $isDefault = false)
    {
        parent::__construct();
        
        $this->set_CaseExpression($CaseExpression);
        
        $Statements == null ?
            $this->Statements = new StatementCollection() :
            $this->set_Statements($Statements);

        $this->set_hasBreak($hasBreak);
        $this->set_isDefault($isDefault);
        
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'CaseExpression')
        {
            $this->set_CaseExpression($value);
        }
        
        if($name == 'Statements')
        {
            $this->set_Statements($value);
        }
        
        if($name == 'hasBreak')
        {
            $this->set_hasBreak($value);
        }
        
        if($name == 'isDefault')
        {
            $this->set_isDefault($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        parent::__get($name);
        
        if($name == 'CaseExpression')
        {
            return $this->get_CaseExpression();
        }
        
        if($name == 'Statements')
        {
            return $this->get_Statements();
        }
        
        if($name == 'hasBreak')
        {
            return $this->get_hasBreak();
        }
        
        if($name == 'isDefault')
        {
            return $this->get_isDefault();
        }
    }
    
    /**
     * The $CaseExpression getter method
     * @return Expression 
     */
    
    public function get_CaseExpression()
    {
        return $this->CaseExpression;
    }

    /**
     * The $CaseExpression setter method
     * @param Expression $CaseExpression 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_CaseExpression(Expression $CaseExpression)
    {
        $this->CaseExpression = $CaseExpression;
    }

    /**
     * The $Statements getter method
     * @return StatementCollection 
     */
    
    public function get_Statements()
    {
        return $this->Statements;
    }

    /**
     * The $Statements setter method
     * @param StatementCollection $Statements 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_Statements(StatementCollection $Statements)
    {
        $this->Statements = $Statements;
    }

    /**
     * The $hasBreak getter method
     * @return bool 
     */
    
    public function get_hasBreak()
    {
        return $this->hasBreak;
    }

    /**
     * The $hasBreak setter method
     * @param bool $hasBreak
     * @throws InvalidArgumentException 
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert ('name') throws InvalidArgumentException
     * @assert (new stdClass()) throws InvalidArgumentException
     */
    
    public function set_hasBreak($hasBreak)
    {
        if(is_bool($hasBreak))
        {
            $this->hasBreak = $hasBreak;
        }
        else
        {
            throw new InvalidArgumentException(
                'The value must be boolean.');
        }
    }

    /**
     * The $isDefault getter method
     * @return bool 
     */
    
    public function get_isDefault()
    {
        return $this->isDefault;
    }

    /**
     * The $isDefault setter method
     * @param bool $isDefault
     * @throws InvalidArgumentException 
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert ('name') throws InvalidArgumentException
     * @assert (new stdClass()) throws InvalidArgumentException
     */
    
    public function set_isDefault($isDefault)
    {
        if(is_bool($isDefault))
        {
            $this->isDefault = $isDefault;
        }
        else
        {
            throw new InvalidArgumentException(
                'The value must be boolean.');
        }
    }

    /**
     * The expression to be compared to switch statement condition
     * @var Expression 
     */
    
    private $CaseExpression;
    
    /**
     * The statements that belong to this case statement
     * @var StatementCollection 
     */
    
    private $Statements;
    
    /**
     * Does this case statement ends with break
     * @var bool 
     */
    
    private $hasBreak;
    
    /**
     * Is this case statement default
     * @var bool 
     */
    
    private $isDefault;
}

?>
